package com.bw.polling.net

import androidx.lifecycle.MutableLiveData
import com.bw.common.vm.BaseViewModel
import com.bw.http.utils.zgr.OkHttpClientManager
import com.bw.polling.entity.PollingEntity

class PollingViewModel:BaseViewModel() {
    val pollingSuccess by lazy { MutableLiveData<List<PollingEntity>>() }

    val apiService: ApiService = OkHttpClientManager.retrofitInstance.create(ApiService::class.java)

    fun getPolling() {

        executeNetwork(
            { apiService.getPolling() },
            pollingSuccess::postValue
        )
    }
    val addPollingSuccess by lazy { MutableLiveData<PollingEntity>() }
    fun addPolling(pollingEntity: PollingEntity){
        executeNetwork(
            {apiService.addPolling(pollingEntity)},
            addPollingSuccess::postValue
        )
    }
    val DeletePollingSuccess by lazy { MutableLiveData<Boolean>() }
    fun delPolling(id:Int){
        executeNetwork(
            {apiService.delPolling(id)},
            DeletePollingSuccess::postValue
        )
    }
}